﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GLYFrom.tcgl
{
    public partial class tc_SeleDele : Form
    {
        public tc_SeleDele()
        {
            InitializeComponent();
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells["Col_Id"].Value);
            tcgl.tc_update from = new tc_update(id);
            from.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string Name = this.text_Name.Text.Trim();
            string JiaGe = this.text_JG.Text.Trim();
            string sql = "select * from T_TaoCan where 1=1";
            if (Name.Length>0)
            {
                sql += string.Format("and TCName like '%{0}%'",Name);
            }
            if (JiaGe.Length > 0)
            {
                sql += string.Format("and TCJG like '%{0}%'", JiaGe);
            }
            DataTable table=DBHelper.select(sql);
            this.dataGridView1.DataSource = null;
            this.dataGridView1.DataSource = table;
        }

        private void tc_SeleDele_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoGenerateColumns = false;
            DataTable table = DBHelper.select("select * from T_TaoCan");
            this.dataGridView1.DataSource = table;
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确定要删除吗？","提示",MessageBoxButtons.OKCancel)==DialogResult.OK)
            {
                int id=Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells["Col_Id"].Value);
                int sr = DBHelper.ZSG(string.Format("delete from T_TaoCan where TCId='{0}'",id));
                if (sr>0)
                {
                    MessageBox.Show("删除成功!");
                }
                else
                {
                    MessageBox.Show("删除失败!");
                }
            }
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataTable table = DBHelper.select("select * from T_TaoCan");
            this.dataGridView1.DataSource = null;
            this.dataGridView1.DataSource = table;
        }
    }
}
